package com.xiaoyu.merchant.ui.activity.order;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.xiaoyu.commonlib.network.CommonHttpResponser;
import com.xiaoyu.commonlib.ui.base.BaseActivityWithTitle;
import com.xiaoyu.merchant.R;
import com.xiaoyu.merchant.model.OrderDetailsBean;
import com.xiaoyu.merchant.network.NetworkManager;
import com.xiaoyu.merchant.ui.fragment.order.OrderFragment;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author jx
 * @date 创建时间 2019/1/3
 * @Description 等待付款详情
 */
public class WaitPaymentActivity extends BaseActivityWithTitle {

    @BindView(R.id.activity_examine_order_name)
    TextView mOrderName;
    @BindView(R.id.activity_examine_order_address_txt)
    TextView mAddress;
    @BindView(R.id.activity_examine_order_store_img)
    ImageView mGoodsImg;
    @BindView(R.id.activity_examine_order_goods_name)
    TextView mGoodsName;
    @BindView(R.id.activity_examine_order_goods_num)
    TextView mGoodsNum;
    @BindView(R.id.activity_examine_order_goods_price)
    TextView mGoodsPrice;
    @BindView(R.id.activity_examine_ordernumber)
    TextView mOrderNumber;
    @BindView(R.id.activity_examine_orderaddtime)
    TextView mOrderTime;


    @Override
    protected void loadContentView(ViewGroup parent) {
        setTitleText("订单详情");
        View mView = LayoutInflater.from(this).inflate(R.layout.activity_wait_payment, parent, true);
        ButterKnife.bind(this);
        initView();
    }

    //初始化
    private void initView() {
        String orderId = getIntent().getStringExtra(OrderFragment.ORDER_ID);//订单id
        getOrderDetalis(orderId);
    }

    private void getOrderDetalis(String orderid) {
        showLoading();
        NetworkManager.orderDetails(orderid, new CommonHttpResponser() {
            @Override
            public void onSuccess(String result) {
                dissmissLoading();
                successWaitPaymentDetails(result);
            }

            @Override
            public void onFailed(String errorCode, String errorDiscription) {
                dissmissLoading();
            }
        });
    }

    private void successWaitPaymentDetails(String result) {
        OrderDetailsBean bean = new Gson().fromJson(result, OrderDetailsBean.class);
        mOrderName.setText(bean.getData().getOrdername() + "   " + bean.getData().getTel());//名字与手机号
        mAddress.setText(bean.getData().getAddress());//地址
        Glide.with(this).load(bean.getData().getDetail().getGoodsdeimg()).into(mGoodsImg);//商品图片
        mGoodsName.setText(bean.getData().getDetail().getGoodsname());//商品名称
        mGoodsNum.setText("数量：" + bean.getData().getDetail().getGoodsnumber());//商品数量
        mGoodsPrice.setText("￥ " + bean.getData().getDetail().getGoodsprice());//商品单价
        mOrderNumber.setText("订单编号：" + bean.getData().getOrdernumber());//订单编号
        mOrderTime.setText("下单时间：" + bean.getData().getOrderaddtime());//下单时间
    }
}
